#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>

Local $sourcePath = "D:\Games\Profiles\wow\Miro\j4f\hbrelogsettings\"
Local $targetPath = "C:\Users\cyris\AppData\Roaming\HighVoltz\HBRelog\"
Local $targetFile = "Setting.xml"


Debug("Starting Profile Shuffle")
Local $sourceFile = GetRandomFile ($sourcePath)

FileCopy($sourcePath & $sourceFile , $targetPath & $targetFile, 1)
If @error Then
   Debug("error file copy: " & $sourcePath & $sourceFile & " --> " & $targetPath & $targetFile)
Else
   Debug("successfull file copy: " & $sourcePath & $sourceFile & " --> " & $targetPath & $targetFile)
EndIf


Func GetRandomFile($_path)
	Local $fileArray[1]

	; Shows the filenames of all files in the directory.
	Local $_search = FileFindFirstFile($_path & "*.*")

	; Check if the search was successful
	If $_search = -1 Then
	    Exit
	EndIf

	$_fileCount = 0
	While 1
		Local $file = FileFindNextFile($_search)
		If @error Then ExitLoop
		;Debug($file)
	    _ArrayAdd($fileArray, $file)
	WEnd

   _ArrayDelete($fileArray, 0)
   Local $String
    If UBound($fileArray) > 1 Then
        $Index = Random(0, UBound($fileArray), 1)
        If $Index > UBound($fileArray) - 1 Then $Index = UBound($fileArray) - 1
        ;Debug('Current (Random) Index = ' & $Index)
        $String = $fileArray[$Index]
    Else
        $String = $fileArray[0]
    EndIf
   ;Debug("Random File" & $String)

	; Close the search handle
	FileClose($_search)
	Return $String
 EndFunc
 
 
 Func Debug($text)
   ConsoleWrite("DEBUG: " & $text & @CRLF)
EndFunc

